package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.accounts.Account;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Student on 14.11.2014.
 */
public class Client implements Serializable {
    private String name;
    private Gender gender;
    private Set<Account> accounts;

    public Client(Set<Account> accounts) {
        this.accounts = accounts;
    }

    public Client(String name, Gender gender, Account account) {
        this.name = name;
        this.gender = gender;
        accounts = new HashSet<Account>();
        accounts.add(account);
    }

    public String getName() {
        return name;
    }

    public Set<Account> getAccounts() {
        return accounts;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Client)) {
            return false;
        }
        Client client = (Client) o;
        if (gender != client.gender) {
            return false;
        }
        if (name != null ? !name.equals(client.name) : client.name != null) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append(gender + " " + name + ": ");
        for (Account account: accounts) {
            result.append(account).append(", ");
        }
        return result.toString();
    }
}

